package cn.sanli.manage.service.impl;


import cn.sanli.manage.mapper.data1.StandardMapper;
import cn.sanli.manage.pojo.dto.User.SaveStandardDTO;
import cn.sanli.manage.pojo.dto.User.StandardEnableDTO;
import cn.sanli.manage.pojo.entity.Standard;
import cn.sanli.manage.service.StandardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 记分提醒标准表(standard)表服务实现类
 *
 * @author makejava
 * @since 2023-12-04 15:34:08
 */
@Service("standardService")
public class StandardServiceImpl implements StandardService {
    @Resource
    private StandardMapper standardMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Standard queryById(Integer id) {
        return this.standardMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增数据
     *
     * @param standard 实例对象
     * @return 实例对象
     */
    @Override
    public Standard insert(Standard standard) {
        this.standardMapper.insert(standard);
        return standard;
    }

    /**
     * 修改数据
     *
     * @param standard 实例对象
     * @return 实例对象
     */
    @Override
    public Standard update(Standard standard) {
        this.standardMapper.update(standard);
        return this.queryById(standard.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.standardMapper.deleteByPrimaryKey(id) > 0;
    }


    /**
     * 获取记分提醒标准列表
     * @return
     */
    @Override
    public List<Standard> findStandardList() {
        List<Standard> standardList = standardMapper.findAllStandard();
        return standardList;
    }

    @Override
    public void saveStandard(SaveStandardDTO info) {
        standardMapper.saveStandard(info);
    }

    @Override
    public void updateStandard(Standard standard) {
        standardMapper.updateSelective(standard);
    }

    @Override
    public void updateIsEnable(StandardEnableDTO isEnable) {
        standardMapper.updateIsEnableById(isEnable.getIsEnable(),isEnable.getId());
    }

    @Override
    public Standard findStandard(Integer id) {
        return standardMapper.selectByPrimaryKey(id);
    }

}

